package com.zryc.shop.sms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.sms.entity.FlashPromotion;
import com.zryc.shop.sms.entity.FlashPromotionSession;
import com.zryc.shop.sms.service.IFlashPromotionService;
import com.zryc.shop.sms.service.IFlashPromotionSessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;

/**
 * <p>
 * 限时购场次表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "秒杀时间段管理接口列表")
@RequestMapping("/sms/flashSession")
public class FlashPromotionSessionController {

    @Autowired
    private IFlashPromotionSessionService flashPromotionSessionService;

    @GetMapping("/list")
    @ApiOperation("查询列表")
    public Result list(){
        System.out.println(123123);
        return Result.ok(flashPromotionSessionService.list());
    }

    @PostMapping("/create")
    @ApiOperation("添加秒杀活动")
    public Result create(@RequestBody FlashPromotionSession session){
        session.setCreateTime(LocalDateTime.now());
        return Result.ok(flashPromotionSessionService.save(session));
    }

    @PostMapping("/update/{id}")
    @ApiOperation("更新秒杀时间段")
    public Result update(@RequestBody FlashPromotionSession session, @PathVariable Long id){
        return Result.ok(flashPromotionSessionService.updateTime(id,session));
    }
    @PostMapping("/delete/{id}")
    @ApiOperation("删除秒杀时间段")
    public Result delete(@PathVariable Long id){
        return Result.ok(flashPromotionSessionService.removeById(id));
    }

    @PostMapping("/update/status/{id}")
    @ApiOperation("修改状态")
    public Result updateStatus(@PathVariable Long id, Integer status){
        return Result.ok(flashPromotionSessionService.updateStatus(id,status));
    }

    @GetMapping("/selectList")
    @ApiOperation("查询活动对应的时间段列表")
    public Result selectList(@RequestParam Long flashPromotionId){
        return Result.ok(flashPromotionSessionService.selectList(flashPromotionId));
    }


}
